const { log } = require("console")
var fs = require("fs")
var http = require("http"); 
const path = require("path");
const en =  http.createServer((request,response)=>{
    console.log("启动成功");
     fs.readFile("public/index.html","utf8",(a,b)=>{  

        console.log(b);
        const en6 =  path.basename('public/index.html')
        console.log(en6.search('html'));
        
        if(en6.search('html')!=-1){
            response.writeHead(200,{
                "content-type":"text/html"
            })
            response.end(b)
        }else if(en6.search('css')!=-1){
            response.writeHead(200,{
                "content-type":"text/css"
            })
            response.end(b)
        } else if(en6.search('javascript')!=-1){
            
                response.writeHead(200,{
                    "content-type":"text/javascript"
                })
                response.end(b)
        }else{     
            response.statusCode = 404 
            response.end("no")
        } 
    })
})
en.listen(8081)